package com.budwk.app.sqfwV2.generator.dayingRoadPdf;

import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.BaseTemplatePdfGenerator;
import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.SqfwPdfCreateCommonBO;
import com.budwk.app.sqfwV2.dto.dayingRoad.DaYingLuWhiteRecordPdfDTO;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.deepoove.poi.data.PictureRenderData;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @author 东方祥云低代码1.1
 * @since 2024-02-21
 * <p>
 * 大营路白事备案表 DaYingLuWhiteRecord
 * PDF红白理事会劝阻工作台账记录表.docx
 */
public class RedAndWhiteDiscourageGenerator extends BaseTemplatePdfGenerator {

    @Override
    public String getTemplateName() {
        return "daYingLu/white/redAndWhiteDiscourage.docx";
    }

    @Override
    public boolean pdfCreateConditionCheck(SqfwPdfCreateCommonBO pdfDTO) {
        DaYingLuWhiteRecordPdfDTO fieldDTO = (DaYingLuWhiteRecordPdfDTO) pdfDTO.getAbstractCustomerPdfCreateField();
        if (!fieldDTO.getIsInFuneralHome() && fieldDTO.getIsGuidanceDissuasionDone()) {
            return true;
        }
        return false;
    }

    @Override
    public void customerPopularPdfParam(Map<String, Object> paramMap, SqfwPdfCreateCommonBO pdfParamBO) {
        // 在这里对一些数据进行填充 进行复杂的业务代码逻辑
        paramMap.put("date", paramMap.get("fillDateStr"));
        // 红白理事会
        String community = paramMap.get("community").toString();
        if (community.contains("社区")) {
            paramMap.put("title", community.substring(0, community.indexOf("社区")) + "居委会");
            paramMap.put("boardOfGovernors", community.substring(0, community.indexOf("社区")) + "居委会红白理事会");
        } else {
            paramMap.put("title", community + "居委会");
            paramMap.put("boardOfGovernors", community + "居委会红白理事会");
        }

        // 图片处理
        Object signature = pdfParamBO.getCustomerParamMap().get("signature");
        List<String> signatureList = Arrays.asList(signature == null ? "" : signature.toString());
        String signatureName = "signature";
        List<Map<String, PictureRenderData>> signatures = CommonFormOfficeUtils.addWordPicture(signatureList, signatureName, 1.0F);
        paramMap.put(signatureName + "s", signatures);
        if (signature != null && StringUtils.isNotBlank(signature.toString())) {
            paramMap.put("createUserName", "");
        }

        // 图片处理
        String url = paramMap.get("visitPictures").toString();
        List<String> pictureUrlList1 = Arrays.asList(url.split(","));
        String fieldName1 = "visitPicture";
        List<Map<String, PictureRenderData>> pictures1 = CommonFormOfficeUtils.addWordPicture(pictureUrlList1, fieldName1, 10.0F);
        paramMap.put(fieldName1 + "s", pictures1);
    }
}
